<?xml version="1.0" encoding="UTF-8"?>
<as:AppSchemaDataAccess xmlns:as="http://www.geotools.org/app-schema"
    xmlns:ogc="http://www.opengis.net/ogc" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.geotools.org/app-schema AppSchemaDataAccess.xsd
                      http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/expr.xsd">
    <namespaces>
        <Namespace>
            <prefix>ex</prefix>
            <uri>http://example.com</uri>
        </Namespace>
        <Namespace>
            <prefix>gml</prefix>
            <uri>http://www.opengis.net/gml/3.2</uri>
        </Namespace>
    </namespaces>
    <sourceDataStores>
        <DataStore>
            <id>DataDirectory</id>
            <parameters>
                <Parameter>
                    <name>directory</name>
                    <!-- path can be relative to this file if starts with 
                        "file: -->
                    <value>file:./</value>
                </Parameter>
            </parameters>
        </DataStore>
    </sourceDataStores>
    <targetTypes>
        <FeatureType>
            <schemaUri>ConnectionUsageTest.xsd</schemaUri>
        </FeatureType>
    </targetTypes>
    <typeMappings>
        <FeatureTypeMapping>
            <sourceDataStore>DataDirectory</sourceDataStore>
            <sourceType>ConnectionUsageParent</sourceType>
            <targetElement>ex:ConnectionUsageParent</targetElement>
            <attributeMappings>
                <AttributeMapping>
                    <targetAttribute>ex:ConnectionUsageParent</targetAttribute>
                    <idExpression>
                        <OCQL>GML_ID</OCQL>
                    </idExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>gml:name</targetAttribute>
                    <sourceExpression>
                        <OCQL>NAME</OCQL>
                    </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>ex:nestedFeature</targetAttribute>
                    <sourceExpression>
                        <OCQL>GML_ID</OCQL>
                        <linkElement>ex:ConnectionUsageFirstNested</linkElement>
                        <linkField>FEATURE_LINK</linkField>
                    </sourceExpression>
                    <isMultiple>true</isMultiple>
                </AttributeMapping>
            </attributeMappings>
        </FeatureTypeMapping>
        <FeatureTypeMapping>
            <sourceDataStore>DataDirectory</sourceDataStore>
            <sourceType>ConnectionUsageFirstNested</sourceType>
            <targetElement>ex:ConnectionUsageFirstNested</targetElement>
            <attributeMappings>
                <AttributeMapping>
                    <targetAttribute>ex:ConnectionUsageFirstNested</targetAttribute>
                    <idExpression>
                        <OCQL>GML_ID</OCQL>
                    </idExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>gml:name</targetAttribute>
                    <sourceExpression>
                        <OCQL>NAME</OCQL>
                    </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>FEATURE_LINK</targetAttribute>
                    <sourceExpression>
                        <OCQL>PARENT_ID</OCQL>
                    </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>ex:nestedFeature</targetAttribute>
                    <sourceExpression>
                        <OCQL>GML_ID</OCQL>
                        <linkElement>ex:ConnectionUsageSecondNested</linkElement>
                        <linkField>FEATURE_LINK</linkField>
                    </sourceExpression>
                    <isMultiple>true</isMultiple>
                </AttributeMapping>
            </attributeMappings>
        </FeatureTypeMapping>
        <FeatureTypeMapping>
            <sourceDataStore>DataDirectory</sourceDataStore>
            <sourceType>ConnectionUsageSecondNested</sourceType>
            <targetElement>ex:ConnectionUsageSecondNested</targetElement>
            <attributeMappings>
                <AttributeMapping>
                    <targetAttribute>ex:ConnectionUsageSecondNested</targetAttribute>
                    <idExpression>
                        <OCQL>GML_ID</OCQL>
                    </idExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>FEATURE_LINK</targetAttribute>
                    <sourceExpression>
                        <OCQL>PARENT_ID</OCQL>
                    </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>gml:name</targetAttribute>
                    <sourceExpression>
                        <OCQL>NAME</OCQL>
                    </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>ex:conditionallyNestedFeature</targetAttribute>
                    <sourceExpression>
                        <OCQL>GML_ID</OCQL>
                        <linkElement>if_then_else(equalTo(NAME, 'A_nested_second'), 'ConditionallyNestedFeature', toXlinkHref('urn:ogc:def:nil:OGC:1.0:missing'))</linkElement>
                        <linkField>FEATURE_LINK</linkField>
                    </sourceExpression>
                    <isMultiple>true</isMultiple>
                </AttributeMapping>
            </attributeMappings>
        </FeatureTypeMapping>
        <FeatureTypeMapping>
            <mappingName>ConditionallyNestedFeature</mappingName>
            <sourceDataStore>DataDirectory</sourceDataStore>
            <sourceType>ConnectionUsageThirdNested</sourceType>
            <targetElement>ex:ConnectionUsageThirdNested</targetElement>
            <attributeMappings>
                <AttributeMapping>
                    <targetAttribute>ex:ConnectionUsageThirdNested</targetAttribute>
                    <idExpression>
                        <OCQL>GML_ID</OCQL>
                    </idExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>FEATURE_LINK</targetAttribute>
                    <sourceExpression>
                        <OCQL>PARENT_ID</OCQL>
                    </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>gml:name</targetAttribute>
                    <sourceExpression>
                        <OCQL>DOES_NOT_EXIST</OCQL>
                    </sourceExpression>
                </AttributeMapping>
            </attributeMappings>
        </FeatureTypeMapping>
    </typeMappings>
</as:AppSchemaDataAccess>
